/**
 * 
 */
package cn.ivicar.passport.service;

import java.util.List;

import com.google.inject.Inject;

import cn.com.carsmart.exception.CarsmartException;
import cn.com.carsmart.ws.ibatis.model.BaseExample;
import cn.com.carsmart.ws.model.Customer;
import cn.com.carsmart.ws.service.CustomerManager;

/**
 * @Author: liurunbin
 * @Description:用户信息管理service层
 * @Date: Created in 2017/5/16
 */
public class PassportService {

	@Inject
	private CustomerManager customerManager;

	/*
	通过手机号获取用户
	 */
	public Customer getByMobile(String mobile) {
		Customer customer = new Customer();
		customer.setMobile(mobile);
		List<Customer> list = this.customerManager.listByExample(customer);
		if (list == null || list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

	/*
	通过ID获取用户
	 */
	public Customer get(Long customerId) {

		return this.customerManager.get(customerId);
	}

	/*
	插入用户
	 */
	public int insert(Customer customer) throws CarsmartException {
		int result = this.customerManager.insert(customer);
		return result;
	}

	/*
	更新用户
	 */
	public int updateSelective(Customer update) throws CarsmartException {
		int result = this.customerManager.updateSelective(update);
		return result;
	}

	/*
	获取用户列表
	 */
	public List<Customer> get(List<Long> cidList) {
		BaseExample example = customerManager.getExample();
		example.or().andPropertyIn(cidList, "id");
		return customerManager.listByBaseExample(example);

	}
}
